package com.pansoft.openplanet.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import androidx.constraintlayout.widget.ConstraintLayout;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.efounder.baseadapter.listview.CommonAdapter;
import com.efounder.baseadapter.listview.ViewHolder;
import com.efounder.chat.activity.BaseActivity;
import com.efounder.utils.ResStringUtil;
import com.pansoft.openplanet.R;

import java.util.Arrays;
import java.util.List;

/**
 * 通用钱包类型选择
 *
 * @author yqs
 */

public class CommonWalletTypeChooseActivity extends BaseActivity implements View.OnClickListener {

    public static int requestCode1 = 1011;
    private ImageView ivBack;
    private TextView tvTitle;

    List<Integer> iamges;
    private ListView listview;

    public static void start(Context context, int requestCode) {
        Intent starter = new Intent(context, CommonWalletTypeChooseActivity.class);
        ((Activity) context).startActivityForResult(starter, requestCode);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.assets_activity_common_wallet_type_choose);
        initView();
        //initListener();

        initData();
    }


    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

    }

    private void initView() {
        //标题
        listview = (ListView) findViewById(R.id.listview);
        tvTitle = (TextView) findViewById(R.id.tv_title);
        ivBack = (ImageView) findViewById(R.id.iv_back);

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == requestCode1 && resultCode == Activity.RESULT_OK) {
            setResult(requestCode1, data);
            finish();
        }

    }

    private void initData() {
        tvTitle.setText(ResStringUtil.getString(R.string.open_planet_choose_wallet_type));
        List<String> titles = Arrays.asList(new String[]{"PWR", "ETH", "BTC", "EOS"});
        iamges = Arrays.asList(new Integer[]{R.drawable.ipasset_wallet_list_eth,
                R.drawable.ipasset_wallet_list_eth, R.drawable.ipasset_wallet_list_btc, R.drawable.ipasset_wallet_list_eos});

        listview.setAdapter(new MyAdater(this, R.layout.assets_item_common_wallet_type_choose, titles));
        listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            }
        });
    }


    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.but_send) {
            //点击发送
        } else if (id == R.id.ll_wallet_layout) {

        }
    }

    public class MyAdater extends CommonAdapter<String> {
        public MyAdater(Context context, int layoutId, List<String> datas) {
            super(context, layoutId, datas);
        }

        @Override
        protected void convert(ViewHolder viewHolder, String item, int position) {
            ConstraintLayout clBackupPrivateKey;
            ImageView ivIcon;
            TextView tvTitle;
            ImageView ivBackupMore;

            clBackupPrivateKey = viewHolder.getView(R.id.cl_backup_private_key);
            ivIcon = (ImageView) viewHolder.getView(R.id.iv_icon);
            tvTitle = (TextView) viewHolder.getView(R.id.tv_title);
            ivBackupMore = (ImageView) viewHolder.getView(R.id.iv_backup_more);
            tvTitle.setText(item);
            ivIcon.setImageDrawable(getResources().getDrawable(iamges.get(position)));

        }
    }
}
